/*
 * reclog.h
 *
 *  Created on: 2011-7-15
 *      Author: lihh
 */

#ifndef RECLOG_H_
#define RECLOG_H_

#include <boost/format.hpp>
#include <log4cxx/logger.h>
#include <log4cxx/basicconfigurator.h>
#include <log4cxx/propertyconfigurator.h>

class RecLogI{
public:
	RecLogI() {}
	virtual ~RecLogI() {}
	virtual bool init(const char* logfile,const char* logname) = 0;
	virtual void fatal(const std::string& msg) = 0;

	virtual void warn(const std::string& msg) = 0;

	virtual void info(const std::string& msg) = 0;

	virtual void debug(const std::string& msg) = 0;

	virtual void trace(const std::string& msg) = 0;
};

class RecLog4C : public RecLogI{
public:
	RecLog4C();
	~RecLog4C();

	bool init(const char* logfile,const char* logname);

	void fatal(const std::string& msg);

	void warn(const std::string& msg);

	void info(const std::string& msg);

	void debug(const std::string& msg);

	void trace(const std::string& msg);

private:
	log4cxx::LoggerPtr _logger;
};

class RecLogFactory{
public:
	~RecLogFactory();
	static void setGlobalLog(RecLogI *log);
	static RecLogI* getGlobalLog();

private:
	RecLogFactory();
	static RecLogFactory _factory;
	RecLogI *_glog;
	bool _isDefaultLog;
};

#define RECFATAL(message)	\
	do{	\
		::log4cxx::helpers::MessageBuffer oss_; \
		RecLogFactory::getGlobalLog()->fatal(oss_.str(oss_ << message));	\
	}while(0)


#define RECWARN(message)	\
	do{	\
		::log4cxx::helpers::MessageBuffer oss_; \
		RecLogFactory::getGlobalLog()->warn(oss_.str(oss_ << message));	\
	}while(0)

#define RECINFO(message)	\
	do{	\
		::log4cxx::helpers::MessageBuffer oss_; \
		RecLogFactory::getGlobalLog()->info(oss_.str(oss_ << message));	\
	}while(0)

#define RECDEBUG(message)	\
	do{	\
		::log4cxx::helpers::MessageBuffer oss_; \
		RecLogFactory::getGlobalLog()->debug(oss_.str(oss_ << message));	\
	}while(0)

#define RECTRACE(message)	\
	do{	\
		::log4cxx::helpers::MessageBuffer oss_; \
		RecLogFactory::getGlobalLog()->trace(oss_.str(oss_ << message));	\
	}while(0)


#endif /* RECLOG_H_ */
